home *** CD-ROM | disk | FTP | other *** search
/ C++ für Kids / C++ for kids.iso / Buch / Monstr8a.cpp < prev    next >
C/C++ Source or Header  |  1999-01-29  |  2KB  |  86 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "Monstr8a.h"
  6. //---------------------------------------------------------------------------
  7. //  TOButton mu▀ als Komponente installiert sein !!!
  8. //---------------------------------------------------------------------------
  9. #pragma link "obutton2"  // Datei: Obutton2.obj
  10. #pragma resource "*.dfm"
  11.  
  12. const String Pfad = "c:\\cpp\\buch\\";
  13.  
  14. class TMonster
  15. {
  16. public:
  17.   virtual void operator >> (String Bild);
  18. };
  19.  
  20. //---------------------------------------------------------------------------
  21.  
  22. TMonster *WerWohl;
  23. bool Modus;
  24. int  Zufall;
  25. TForm1 *Form1;
  26.  
  27. //---------------------------------------------------------------------------
  28. __fastcall TForm1::TForm1(TComponent* Owner)
  29.     : TForm(Owner)
  30. {
  31. }
  32. //---------------------------------------------------------------------------
  33. void TMonster::operator >> (String Bild)
  34. {
  35.   String Name = Bild.SubString(1, Bild.Length()-4);
  36.   Form1->Image1->Picture->LoadFromFile (Pfad+Bild);
  37.   Form1->Panel1->Caption = Name;
  38. }
  39. //---------------------------------------------------------------------------
  40. void __fastcall TForm1::FormCreate(TObject *Sender)
  41. {
  42.   randomize ();
  43.   WerWohl = new TMonster;
  44.   Timer1->Interval = 500;
  45.   Timer1->Enabled = false;
  46.   Modus = true;
  47. }
  48. //---------------------------------------------------------------------------
  49. void __fastcall TForm1::OButton1Click(TObject *Sender)
  50. {
  51.   if (Modus)
  52.   {
  53.     Timer1->Enabled = true;
  54.     Label1->Caption = "Stop";
  55.   }
  56.   else
  57.   {
  58.     Timer1->Enabled = false;
  59.     Label1->Caption = "Start";
  60.   }
  61.   Modus = !Modus;
  62. }
  63. //---------------------------------------------------------------------------
  64. void __fastcall TForm1::Timer1Timer(TObject *Sender)
  65. {
  66.   Zufall = random(5);
  67.   switch (Zufall)
  68.   {
  69.     case 0:
  70.       *WerWohl >> "Frank.bmp";
  71.       break;
  72.     case 1:
  73.       *WerWohl >> "Albert.bmp";
  74.       break;
  75.     case 2:
  76.       *WerWohl >> "Sigmund.bmp";
  77.       break;
  78.     case 3:
  79.       *WerWohl >> "Jekyll.bmp";
  80.       break;
  81.     case 4:
  82.       *WerWohl >> "Hyde.bmp";
  83.   }
  84. }
  85. //---------------------------------------------------------------------------
  86.